import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../model/cart_model.dart';
import '../../provide/cart_provide.dart';
import 'package:provide/provide.dart';


class CartCount extends StatelessWidget {
  final CartInfoModel item;
  CartCount(this.item);


  @override
  Widget build(BuildContext context) {
    
    return Container(
      width: ScreenUtil().setWidth(165),
      margin: EdgeInsets.only(top:5.0),
      decoration: BoxDecoration(
        border: Border.all(
          width: 0.5,color: Colors.black12
        )
      ),
      child: Row(
       children: <Widget>[
          _reduceBtn(context,item),
          _countArea(item),
          _addBtn(context,item),
       ],
      ),
    );
  }



  // 减号
  Widget _reduceBtn(context,item){
    return InkWell(
      onTap: (){
        Provide.value<CartProvide>(context).reduceGoodsNum(item.goodsId);
      },
      child: Container(
        width: ScreenUtil().setWidth(45.0),
        height: ScreenUtil().setHeight(45.0),
        alignment: Alignment.center,
        decoration: BoxDecoration(
          color: Colors.white,
          border: Border(
            right: BorderSide(width: 0.5,color:Colors.black12)
          )
        ),
        child: Text('-'),
      ),
    );
  }


  // 加号
  Widget _addBtn(context,item){
    return InkWell(
      onTap: (){
        print('nijjf');
        Provide.value<CartProvide>(context).addGoodsNum(item.goodsId);
      },
      child: Container(
        width: ScreenUtil().setWidth(45.0),
        height: ScreenUtil().setHeight(45.0),
        alignment: Alignment.center,
        decoration: BoxDecoration(
          color: Colors.white,
          border: Border(
            left: BorderSide(width: 0.5,color:Colors.black12)
          )
        ),
        child: Text('+'),
      ),
    );
  }

  // 中间显示数量
  Widget _countArea(CartInfoModel item){
    return Container(
      width: ScreenUtil().setWidth(70.0),
      height: ScreenUtil().setHeight(45.0),
      alignment: Alignment.center,
      color:Colors.white,
      child: Text(item.count.toString()),
    );
  }
}